﻿using System;

using System.Collections.Generic;
using System.Text;
using System.Collections.Specialized;

namespace PasswordSafe.Classes
{
    [Serializable]
    public class PasswordData:NotifyItemBase
    {
        public string Name { 
            get { return GetValues("name"); } 
        }

        private string GetValues(string name)
        {
            string value = Values[name];
            return value != null ? value : string.Empty;
        }

        public string User { get { return GetValues("user"); } }

        public string Password { get { return GetValues("password"); } }

        public string EMail { get { return GetValues("email"); } }

        public string Url { get { return GetValues("url"); } }

        public string Info { get { return GetValues("info"); } }

        private PasswordCategory category;
        public PasswordCategory Category 
        {
            get { return category; }
            set
            {
                if (category != value)
                {
                    if (category != null) category.Remove(this);
                    category = value;
                    if (category != null) category.Add(this);
                }

            }
        }


        private NameValueCollection values = new NameValueCollection();

        public NameValueCollection Values { get { return values; } }

        internal string GetUser()
        {
            return User ?? string.Empty;
        }

        internal string GetPassword()
        {
            return Password ?? string.Empty;
        }
    }
}
